(function ($) {
	Util.loading = function (options) {
		var self = this,
			config = $.extend({
				id            : "body", // 指定一个模块显示遮罩层，请将该元素id的选择串传入，如 id: "#test"
				modal         : true,
				maskAlphaColor: '#ffffff',
				maskAlpha     : 0.8,
				zIndex        : 91000,
				timeout       : 0,  // 数值大于0时，将自动关闭
				name          : (new Date()).valueOf(),
				target        : window.self,
				message       : [
					"很努力的为您加载中。。。",
					"正在加载。。。",
					"吃奶的力气加载中。。。",
					"强势加载中。。。",
					"疯狂的加载中。。。",
					"争分夺秒的加载中。。。",
					"任劳任怨的加载中。。。"
				]
		}, options || {}),
		
		getWindowSize = function(){ 
			var size = {
				width: $(config.target.window).width(),
				height: $(config.target.window).height()
			};
			return size;
		};
		
		if (typeof config.message != "string") {
			var i = parseInt(config.message.length * Math.random());
			config.message = config.message[i];
		}
		
		var w, h, maskDiv;
		if (config.id == "body") {
			w = Math.max($(config.target.document).width(), getWindowSize().width);
			h = Math.max($(config.target.document).height(), getWindowSize().height);
		} else {
			if ($(config.id, config.target.document).css("position") == "static") {
				$(config.id, config.target.document).css("position", "relative");
				config.eleHasPosition = true;
			}
			
			w = $(config.id, config.target.document).width();
			h = $(config.id, config.target.document).height();
		}
		
		if(config.modal){
			maskDiv = "<div id='loading_" + config.name + "_panel' class='loading-panel' style='background:"+config.maskAlphaColor+";position:absolute;width:"+ w +"px;height:"+ h +"px;top:0;left:0;text-align:center;opacity:"+ config.maskAlpha +";filter:alpha(opacity="+ config.maskAlpha * 100 +");z-index:" + (config.zIndex-1) + ";'></div>";
		}else{
			maskDiv = "<div id='loading_" + config.name + "_panel' class='loading-panel' style='position:absolute;width:0;height:0x;top:0;left:0;display:none;text-align:center;z-index:" + (config.zIndex-1) + ";'></div>";
		}
		
		var ie6Iframe = ($.browser.msie&&($.browser.version == "6.0")) ? ('<iframe width="100%" height="100%" style="position:absolute; top:0px; z-index:-1; border-style:none;"></iframe>') : '',
			showDiv = "<div id='loading_" + config.name + "_message' class='loading-message' style='position:absolute;left:0;right:0;text-align:center;top:"+ h / 2.5 +"px;z-index:" + config.zIndex + ";'>" + ie6Iframe;
			showDiv += "<span class='icon'>" + config.message + "</span>";
			showDiv += "</div>";
	
		if ($("#loading_" + config.name + "_panel", config.target.document).size() > 0) {
			$("#loading_" + config.name + "_panel", config.target.document).show(0);
			$("#loading_" + config.name + "_message", config.target.document).show(0);
		} else {
			$(config.id, config.target.document).append(maskDiv);
			$(config.id, config.target.document).append(showDiv);
		}
		
		var remove =  function () {
			if (config.eleHasPosition) {
				$(config.id, config.target.document).css("position", "static");
			}
			$("#loading_" + config.name + "_panel", config.target.document).remove();
			$("#loading_" + config.name + "_message", config.target.document).remove();
		}
		
		if (config.timeout > 0) {
			setTimeout(function () {
				remove();
			}, config.timeout);
		}
	
		return {
			remove: remove
		};
	}
}(jQuery));